package com.someclip.component.controlls
{
	import com.someclip.component.core.Component;
	import com.someclip.component.events.ComponentEvent;
	import com.someclip.component.interfaces.ICheckBox;
	import com.someclip.component.skins.DefaultButtonSkin;
	import com.someclip.component.skins.DefaultFlatSkin;

	import flash.events.Event;
	import flash.events.MouseEvent;

	public class CheckBox extends Component implements ICheckBox
	{
		private var _label:String="Label";
		private var _selected:Boolean=false;
		private var _box:IconButton;
		private var _checker:Component;
		private var _labelIns:Label;
		private var _boxStyle:Object=new DefaultButtonSkin();
		private var _checkStyle:Object=new DefaultFlatSkin(0x00ff00);

		public function CheckBox()
		{
			this.width=75;
			this.height=20;
			this.buttonMode=true;
			_box=new IconButton();
			_box.styleLink=_boxStyle;
			_box.iconStyle=_checkStyle;
			_box.width=this.height - 4;
			_box.height=this.height - 4;
			_box.vCenter=0;
			_box.left=2;
			addChild(_box);
			_labelIns=new Label();
			_labelIns.selectAble=false;
			_labelIns.width=this.width - _box.width - 4;
			_labelIns.height=this.height;
			_labelIns.left=_box.width + 6;
			_labelIns.vCenter=0;
			_labelIns.text=_label;
			addChild(_labelIns);
			_box.iconVisible=_selected;
			this.addEventListener(MouseEvent.CLICK, mouseClickHandler);
		}

		public function get checkStyle():Object
		{
			return _checkStyle;
		}

		public function set checkStyle(value:Object):void
		{
			_checkStyle=value;
			if (_box)
				_box.iconStyle=_checkStyle;
		}

		public function get boxStyle():Object
		{
			return _boxStyle;
		}

		public function set boxStyle(value:Object):void
		{
			_boxStyle=value;
			if (_box)
				_box.styleLink=_boxStyle;
		}

		protected function mouseClickHandler(event:MouseEvent):void
		{
			this.selected=!this.selected;
			this.dispatchEvent(new Event(ComponentEvent.COMPONENT_CHANGED, true));
		}

		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(value:Boolean):void
		{
			_selected=value;
			_box.iconVisible=_selected;
		}

		public function get label():String
		{
			if (_labelIns)
				return _labelIns.text;
			return _label;
		}

		public function set label(value:String):void
		{
			_label=value;
			if (_labelIns)
				_labelIns.text=value;
		}

		/**
		 * 获取字体大小
		 * @return
		 *
		 */
		public function get fontSize():uint
		{
			return _labelIns.fontSize;
		}

		/**
		 * 设置字体大小
		 * @param value
		 *
		 */
		public function set fontSize(value:uint):void
		{
			_labelIns.fontSize=value;

		}

		/**
		 * 获取字体加粗
		 * @return 布尔值
		 *
		 */
		public function get fontWeight():Boolean
		{
			return _labelIns.fontWeight;
		}

		/**
		 * 设置字体加粗
		 * @param value Boolean
		 *
		 */
		public function set fontWeight(value:Boolean):void
		{
			_labelIns.fontWeight=value;
		}

		/**
		 * 获取字体颜色
		 * @return
		 *
		 */
		public function get fontColor():uint
		{
			return _labelIns.fontColor;
		}

		/**
		 * 设置字体颜色
		 * @param value
		 *
		 */
		public function set fontColor(value:uint):void
		{
			_labelIns.fontColor=value;
		}

		/**
		 * 获取文本对齐方式
		 * @return
		 *
		 */
		public function get textAlign():String
		{
			return _labelIns.textAlign;
		}

		/**
		 * 设置文本对齐方式
		 * @param value
		 *
		 */
		public function set textAlign(value:String):void
		{
			_labelIns.textAlign=value;
		}
	}
}
